export default {
    state: {
        userInfo:null,
        token:null,
        onlineStatus:'',
        chatlist:[],
        uuid: ''
    },
    getters: {

    },
    mutations: {
        SET_USERINFO: (state, info) => {
            state.userInfo = info
        },
        SET_TOKEN: (state, token) => {
            //保存token
            localStorage['token'] = token;
            state.token = token;
        },
        SET_UUID: (state, uuid) => {
            sessionStorage['uuid'] = uuid;
            state.uuid = uuid;
        },
        LOGIN_OUT: (state) => {
            state.onlineStatus = '0';
        },
        HEART_BEAT: (state) => {
            console.log('HEART_BEATHEART_BEAT');
        },
        GET_CHAT_CONFIG: (state) => {
            console.log('GET_CHAT_CONFIG');
        }
    },
    actions: {
        getUserInfo ({commit, dispatch}) {//获取客服人员信息
            return new Promise((resolve, reject) => {
                this.$socket.emit('getUserInfo',{
                    "c_id": "40004",
                    "c_t": "0",
                    "s_id": "3",
                    "is_en": "0",
                    "w_k": "e12906e0-831e-11e8-a050-e342921b4d56",
                    "crc": "qweasd",
                    "tk": state.token,
                    "bd":{
                        "tk": "753951466321",
                        "c_s_id": "112233445566",
                        "co_id": "12345678"
                    }
                }, res =>{
                    resolve(res);
                    commit('SET_USERINFO', res);
                })
            })
        },
        setToken ({commit},token) {//设置token
            commit('SET_TOKEN', token);
        },
        setUuid ({commit}, uuid) {
            commit('SET_UUID', uuid);
        },
        startHeartBeat ({commit}) {
            commit('HEART_BEAT');//心跳检测
        },
        loginOut ({commit, dispatch}) {
            commit('LOGIN_OUT');//退出，清除数据
        },
        getChatConfig ({commit}) {
            commit('GET_CHAT_CONFIG');
        }
    }
}